home *** CD-ROM | disk | FTP | other *** search
- # CVS $Id: hlist.tcl,v 1.3 1995/04/29 16:07:24 zibi Exp $
- #
- # This creates a drawn list with some extra data to maintain
- # a hierarch of records
- #
- proc VxExpandoList {dlist addProc fmt args} {
-
- set dlist [eval VtDrawnList $dlist $args]
-
- set fmt [linsert $fmt 0 {DATA}]
-
- # Associate format and count to this list
- #
- VxSetVar $dlist format $fmt
- VxSetVar $dlist count 0
-
- return $dlist
- }
-
- #
- # This deletes all positions
- # below pos that have a greater level.
- #
- proc VxExpandoCollapse {dlist pos} {
- set count [VxGetVar $dlist count]
-
- if {$pos >= $count} {
- return
- }
-
- VxExpandoDeleteItem $dlist $pos on
- }
-
- proc VxExpandoGetLevel {dlist pos} {
-
- set record [VtDrawnListGetItem $dlist -position $pos]
- set record [lindex $record 0]
-
- set recordLevel [lindex $record 0]
- return $recordLevel
- }
-
- proc VxExpandoGetIcon {dlist pos} {
-
- set record [VtDrawnListGetItem $dlist -position $pos]
- set record [lindex $record 0]
-
- set icons [lindex $record 1]
- set end [llength $icons]
- return [lrange $icons $end end]
- }
-
- proc VxExpandoSetIcon {dlist pos icon} {
- set record [VtDrawnListGetItem $dlist -position $pos]
- set record [lindex $record 0]
-
- set icons [lindex $record 1]
- set icons [lreplace $icons end end $icon]
- set record [lreplace $record 1 1 $icons]
- VtDrawnListSetItem $dlist -position $pos -fieldList $record
- }
-
- proc VxExpandoGetRecord {dlist pos level icon rec} {
-
- set record [VtDrawnListGetItem $dlist -position $pos]
- set record [lindex $record 0]
-
- set icons [lindex $record 1]
-
- upvar 1 $icon rIcon $rec rRecord $level rLevel
-
- set rLevel [lindex $record 0]
- set end [llength $icons]
- set rIcon [lrange $icons $end end]
- set rRecord [lrange $record 2 end]
- }
-
- #
- # The next two functions return true if the icon has a
- # upwards or downward connector component
- #
- proc hasDown {icon} {
- switch $icon {
- CONNECT_I -
- CONNECT_T {
- return 1
- }
- default {
- return 0
- }
- }
- }
-
- proc hasUp {icon} {
- switch $icon {
- CONNECT_L -
- CONNECT_I -
- CONNECT_T {
- return 1
- }
- default {
- return 0
- }
- }
- }
-
- #
- # Sets the icon connector for the n'th record in the dlist
- #
- # dlist - DrawnList
- # n - position of record in the drawnlist
- # col - position of icon in the record. The icons are in the second
- # elements of the record.
- # connector - connector to set to.
- #
- proc setIconConnector {dlist n col connector} {
- set rec [VtDrawnListGetItem $dlist -position $n]
- set rec [lindex $rec 0]
-
- set icons [lindex $rec 1]
- if {$col < [llength $icons]} {
- set icons [lreplace $icons $col $col $connector]
- }
-
- set rec [lreplace $rec 1 1 $icons]
-
- VtDrawnListSetItem $dlist -position $n -fieldList $rec
- }
-
- proc getIconConnector {dlist n col} {
- set rec [VtDrawnListGetItem $dlist -position $n]
- set rec [lindex $rec 0]
-
- set icons [lindex $rec 1]
- if {$col < [llength $icons]} {
- return [lindex $icons $col]
- } else {
- return ""
- }
- }
-
- #
- # "Patches" all the connectors to the left of the current
- # record up the next record that has the same level.
- #
- # dlist - drawnlist
- # pos - record position to start the patch
- # level - level of the heirarchy
- # cmd - "ADD" or "SUB" to add or subtract a vertical component.
- #
- proc patchConnectors {dlist pos level cmd} {
- set indx [expr $level - 1]
- while {1} {
- set icon [getIconConnector $dlist $pos $indx]
- set rLevel [VxExpandoGetLevel $dlist $pos]
-
- if {$cmd == "ADD"} {
- if {$icon == "NO_ICON"} {
- set icon CONNECT_I
- } elseif {$icon == "CONNECT_L"} {
- set icon CONNECT_T
- }
- } else {
- echo "icon $icon pos $pos"
- echo "rLevel $rLevel $level "
-
- if {$icon == "CONNECT_I"} {
- set icon NO_ICON
- } elseif {$icon == "CONNECT_T"} {
- set icon CONNECT_L
- }
- }
-
- setIconConnector $dlist $pos $indx $icon
-
- incr pos -1
- if {$rLevel <= $level} {break}
- }
- }
-
- #
- # This proc analyzes the icon connectors. It gets the connector information
- # for the current position and will generate a connector list based
- # on that position.
- proc _analyzeConnect {dlist pos level icon} {
- if {$level == 0} { return $icon }
-
- set count [VxGetVar $dlist count]
- if {$pos == 0} {set pos $count}
-
- # Get the record above and below the one we want to insert
- set aboveRec [VtDrawnListGetItem $dlist -position [expr $pos - 1] ]
- set aboveRec [lindex $aboveRec 0]
-
- if {$pos < $count} {
- set belowRec [VtDrawnListGetItem $dlist -position [expr $pos]]
- set belowRec [lindex $belowRec 0]
- } else {
- set belowRec ""
- }
-
- set aboveIcons [lindex $aboveRec 1]
- set belowIcons [lindex $belowRec 1]
- set currentIcons ""
-
- # analyze all position up to the one before the icon
- set endLevel [expr $level - 1]
- for {set i 0} {$i < $endLevel} {incr i} {
- set abvIcon [lindex $aboveIcons $i]
- set blwIcon [lindex $belowIcons $i]
-
- if {[hasDown $abvIcon] && [hasUp $blwIcon]} {
- lappend currentIcons CONNECT_I
- } else {
- lappend currentIcons NO_ICON
- }
- }
-
- # analyze the connector position just before the icon
- set abvIcon [lindex $aboveIcons $endLevel]
- set blwIcon [lindex $belowIcons $endLevel]
- # echo $abvIcon .. $blwIcon ++ $aboveRec
-
- if {[hasUp $blwIcon]} {
- lappend currentIcons CONNECT_T
- } else {
- lappend currentIcons CONNECT_L
- }
-
- lappend currentIcons 4 $icon
-
- return $currentIcons
- }
-
- proc isConnector {i} {
- switch $i {
- NO_ICON -
- CONNECT_L -
- CONNECT_I -
- CONNECT_T {
- return 1
- }
- default {
- return 0
- }
- }
- }
-
- #
- # dlist - drawnlist to add to
- # pos - position to add to
- # level - record level
- # icon - pixmap to use for this record
- # data - formatList data
- proc VxExpandoAddItem {dlist pos level icon data} {
- #
- # Get dlist info
- set count [VxGetVar $dlist count]
- set fmt [VxGetVar $dlist format]
-
- set fmt [_genFormat $fmt $level]
- set connectors [_analyzeConnect $dlist $pos $level $icon]
-
- set data [linsert $data 0 $level $connectors]
-
- eval [list VtDrawnListAddItem $dlist -formatList $fmt -fieldList $data \
- -position $pos ]
-
- if {$pos == 0} {
- set pos $count
- } else {
- incr pos -1
- }
-
- # Now fix all the connectors between the current one and all
- # above
- if {$level > 0} {
- patchConnectors $dlist $pos $level ADD
- }
-
- incr count 1
-
- VxSetVar $dlist count $count
- }
-
- #
- # This deletes an items in the hlist. If you delete a container record
- # it'll delete all items in the container.
- #
- proc VxExpandoDeleteItem {dlist pos {collaspe off} } {
- set count [VxGetVar $dlist count]
- set startLevel [VxExpandoGetLevel $dlist $pos]
-
- if {[getIconConnector $dlist $pos [expr $startLevel-1]] == "CONNECT_L"} {
- set patch on
- } else {
- set patch off
- }
-
- if {$collaspe} {incr pos}
-
- while {$pos <= $count} {
- VtDrawnListDeleteItem $dlist -position $pos
-
- incr count -1
- if {$count == 0 || $pos > $count} {break}
-
- set level [VxExpandoGetLevel $dlist $pos]
-
- if {$level <= $startLevel} {break}
- }
-
- if {$patch} {
- incr pos -1
- patchConnectors $dlist $pos $startLevel SUB
- }
-
- # Select the next item
- if {$count} {
- if {$pos > $count} { set pos 1 }
- VtDrawnListSelectItem $dlist -position $pos
- }
-
- VxSetVar $dlist count $count
- }
-
- #
- # This sets the width of the icon connector column
- #
- proc _genFormat {userFormat level} {
-
- set fList [list ICON [expr $level+2] ]
-
- set fmt [linsert $userFormat 1 $fList]
- return $fmt
- }
-
- # ----------------------------------------------------------------------
-
- proc addBogus {dlist pos level} {
-
- incr pos
-
- set bigStr "WWWWWWWWAAAAAAAAAAWWAWSA01234566"
- VxExpandoAddItem $dlist $pos $level 0 { "New 1.9" "hide" "hide"}; incr pos
- VxExpandoAddItem $dlist $pos $level 2 { "New 2.9" "hide" "hide"}; incr pos
- VxExpandoAddItem $dlist $pos $level 0 $bigStr
- }
-
- #
- # This routine adds three icons underneath the current directory
- #
- proc addCB {cbs} {
- set dlog [keylget cbs dialog]
-
- set dlist [VxGetVar $dlog dlist]
-
- set pos [VtDrawnListGetSelectedItem $dlist -byPositionList]
-
- VxExpandoGetRecord $dlist $pos level icon record
-
- if {$icon == 0} {
- VxExpandoSetIcon $dlist $pos 1
- addBogus $dlist $pos [expr $level + 1]
- }
- }
-
- proc deleteCB {cbs} {
- set dlog [keylget cbs dialog]
-
- set dlist [VxGetVar $dlog dlist]
-
-
- set pos [VtDrawnListGetSelectedItem $dlist -byPositionList]
-
- VxExpandoDeleteItem $dlist $pos
- }
-
- proc defaultCB {cbs} {
- set dlog [keylget cbs dialog]
-
- set dlist [VxGetVar $dlog dlist]
-
- set pos [VtDrawnListGetSelectedItem $dlist -byPositionList]
- VxExpandoGetRecord $dlist $pos level icon record
-
- if {$icon == 0} {
- VxExpandoSetIcon $dlist $pos 1
- addBogus $dlist $pos [expr $level + 1]
- } elseif {$icon == 1} {
- VxExpandoSetIcon $dlist $pos 0
- VxExpandoCollapse $dlist $pos
- }
- }
-
- proc QuitCB {cbs} {
- VtClose
- exit
- }
-
- set ap [VtOpen hlist]
-
- set dlog [VtFormDialog $ap.form \
- -okCallback addCB -okLabel Add \
- -applyCallback QuitCB -applyLabel "Quit" \
- -cancelCallback deleteCB -cancelLabel Delete ]
-
- set dlist [VxExpandoList $dlog.list \
- addCB {{STRING 20 5} {DATA} {DATA}} \
- -iconList {dir.px odir.px exec.px file.px check.px} \
- -rows 14 -columns 20 \
- -horizontalScrollBar 1 \
- -labelList {"icon" "abcdefghijklmnopqur1234567892jdjfkl"} \
- -labelFormatList {{ICON 1} {STRING 20}} \
- -defaultCallback defaultCB \
- -rightSide FORM -bottomSide FORM ]
-
- VtShow $dlog
-
- VxExpandoAddItem $dlist 0 0 1 { "Hello 1" "hide" "hide"}
- VxExpandoAddItem $dlist 0 1 1 { "Hello 2" "hide" "hide"}
- VxExpandoAddItem $dlist 0 2 0 { "Hello 3" "hide" "hide"}
- VxExpandoAddItem $dlist 0 2 0 { "Hello 4" "hide" "hide"}
- VxExpandoAddItem $dlist 0 2 1 { "Hello 5" "hide" "hide"}
- VxExpandoAddItem $dlist 0 3 0 { "Hello 6" "hide" "hide"}
- VxExpandoAddItem $dlist 0 2 0 { "Hello 7" "hide" "hide"}
- VxExpandoAddItem $dlist 0 1 1 { "Hello 8" "hide" "hide"}
- VxExpandoAddItem $dlist 0 2 0 { "Hello 9" "hide" "hide"}
- VxExpandoAddItem $dlist 0 3 0 { "Hello a" "hide" "hide"}
- VxExpandoAddItem $dlist 0 1 0 { "Hello b" "hide" "hide"}
- VxExpandoAddItem $dlist 0 1 0 { "Hello c" "hide" "hide"}
- VxExpandoAddItem $dlist 0 0 0 { "Hello d" "hide" "hide"}
-
- VxExpandoAddItem $dlist 11 1 0 { "Hello between" "hide" "hide"}
-
- VxSetVar $dlog dlist $dlist
-
- VtDrawnListSelectItem $dlist -position 3
-
- VtMainLoop
-
-
-